﻿package org.dm.3d.Actions.cameras 
{
	import org.dm.3d.geom.Num3D;
	import org.dm.3d.cameras.CameraBase;
	
	/**
	 * ...
	 * @author Scott
	 */
	public class MouseTurn extends CAction
	{
		private var _cur:uint;
		private var w:Number;
		private var h:Number;
		private var _pre:Boolean;
		private var _down:Boolean;
		private var t1:uint;
		private var t2:uint;
		
		public function MouseTurn(pw:Number,ph:Number) 
		{
			w = pw;
			h = ph;
			this.isUsed = true;
			_cur = 0;
			_pre = true;
			_down = false;
			t1 = 5;
			t2 = 10;
		}
		public override function update(items:CameraBase):void 
		{
			items.damping = 1;
			_cur++;
			if (_pre) {
				addT1(items);
				return;
			}
			if (_down && _cur == t1+1)
			{
				addT2(items);
				return;
			}
			if (_cur == t1 + t2+1) {
				items.angleA.x = 0;
				items.angleA.y = 0;/**/
				//items.angle.x = 0;
			}
		}
		private function addT1(pitem:CameraBase):void 
		{
			//pitem.reset();
			pitem.angleA.x = 0;
			pitem.angleSpeed.x = 0;
			pitem.angleSpeed.y = 0;
			pitem.damping = 1;
			pitem.angleA.x = 2 * w / (t1 * (t1 + t2));
			pitem.angleA.y = 2 * h / (t1 * (t1 + t2));
			_pre = false;
		}
		private function addT2(pitem:CameraBase):void 
		{
			pitem.angleA.x = -2 * w / (t2 * (t1 + t2));
			pitem.angleA.y = -2 * h / (t2 * (t1 + t2));
		}
	}
	
}